package com.flx.cloud.shop.user.service.impl;

import com.flx.cloud.shop.user.entity.User;
import com.flx.cloud.shop.user.mapper.UserMapper;
import com.flx.cloud.shop.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;

/**
 * @Author Fenglixiong
 * @Create 2022/5/3 4:04
 * @Description
 **/
@Slf4j
@Service
@RefreshScope
public class UserServiceImpl implements UserService {

    @Value("${system.user.name:default}")
    public String systemUser;

    @Autowired
    private UserMapper userMapper;

    public User get(Long id)throws Exception{
        return userMapper.selectById(id);
    }

    public int add(User user)throws Exception{
        return userMapper.insert(user);
    }

    public int update(User user)throws Exception{
        return userMapper.updateById(user);
    }

    public int delete(Long id)throws Exception{
        return userMapper.deleteById(id);
    }

    public String getSystemUser()throws Exception{
        log.info("from nacos systemUser = {}",systemUser);
        return systemUser;
    }

}
